const BaseRest = require('../rest.js');

module.exports = class extends BaseRest {
  async indexAction() {
    // let data = await this.model("user").select();
    let model = this.model('user');
    let data = await model.page(this.get('page'), this.get('num')).countSelect();
    console.log(data);
    return this.success(data);
  }

  async addAction() {
    let model = this.model('user');
    // let insertId = await this.model('user').add({
    //   title: '标题标题标题',
    //   img: 'http://upyun.h800.com.cn/goods/1530178711515.jpg!/sq/1000',
    //   section: '你花了多少年才...'
    // });
    let insertId = await model.addMany([
      {
        title: '标题标题标题',
        img: 'http://upyun.h800.com.cn/goods/1530178711515.jpg!/sq/1000',
        section: '你花了多少年才...'
      },
      {
        title: '西西',
        img: 'http://img.hb.aicdn.com/5b7ba38c89b2d84fcff26b7062ad1a29b80c99df27afa-SOMWFG_fw658',
        section: '嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻'
      },
      {
        title: 'Sunrise',
        img: 'http://img.hb.aicdn.com/ec9abc7ce74d3f935fbd03f84873422e52a01a1b16131-VBvlWG_fw658',
        section: '如果有来生'
      },
      {
        title: 'strawberry',
        img: 'http://img.hb.aicdn.com/41573037f98a122ecf6a499d55e8caf35cc3101b47ccc-MPVDa1_fw658',
        section: '哈哈哈哈哈哈哈哈哈'
      }
    ]);
    let data = await model.select();
    return this.success(data);
  }

  async delAction() {
    // let model = this.model('user');
    // let affectedRows = await this.model('user').where({id: ['<', 7]}).delete();
    // let data = await this.model("user").select();
    // return this.success(data);
    // let insertId = await this.model('user').add({title: '标题标题标题', img: 'http://upyun.h800.com.cn/goods/1530178711515.jpg!/sq/1000', section: '你花了多少年才...'});
  }
};
